package org.brisling.supply.queryService;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.domain.ListDomain;
import org.brisling.base.domain.inf.BaseTreeNodeInf;
import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.supply.domain.SupplyBaseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/supplyBasetype/query")
public class QuerySupplybasetypeService extends AbstractBaseQueryService<SupplyBaseType>{
	
	@Autowired
	private QueryBaseinfoService qryBaseinfoService;
	
	public QuerySupplybasetypeService(){
		this.moduleName = ConstSysParam.MODULE_SUPPLY_BASETYPE;
		this.subSystem = ConstSysParam.SUBSYSTEM_SUPPLY;
		this.tableName = "V_" +this.getTableName(SupplyBaseType.class);
		this.clazz = SupplyBaseType.class;
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	@RequestMapping("/mainPage.action")
	public ModelAndView getMainPage(){
		return this.getBizMainPage();
	}
	
	/* (non-Javadoc)
	 * @see org.brisling.service.sysman.DepartmentServiceInf#getEditPage()
	 */
	@RequestMapping("/editPage.action")
	public ModelAndView getEditPage(){
		return this.getBizEditPage();
	}	
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("/getListDomain.action")
	public ListDomain<LinkedHashMap> getListDomain(@RequestParam(value="page",required=false) Integer page,
			@RequestParam(value="rows",required=false) Integer rows,
			@RequestParam(value="sort",required=false) String sort){		
		
		
		return super.getPagedListDomain(page, rows);
	}	
	
	@RequestMapping("/getTreeListDomain.action")
	public ListDomain<SupplyBaseType> getTreeListDomain(@RequestParam(value="id",required=false) Long id){
		
		return this.getPagedTreeListDomain(id);
		
	}	
	
	@RequestMapping("/getTreeList.action")
	public List<SupplyBaseType> getTreeList(@RequestParam(value="id",required=false) Long id){
		
		List<SupplyBaseType> lists = this.getPagedTreeList(id);
		return lists;
		
	}
	
	/**
	 * 合并查询节点
	 * @param id
	 * @return
	 */
	@RequestMapping("/getConbinTree.action")
	public List<BaseTreeNodeInf> getConbinTree(@RequestParam(value="id",required=false) Long id){
		
		List<BaseTreeNodeInf> nodeList = new ArrayList<BaseTreeNodeInf>();
		List<SupplyBaseType> typeList= this.getPagedTreeList(id);
		if(typeList!=null && typeList.size()>0)
			nodeList.addAll(typeList);
		
		List<BaseTreeNodeInf> detailList=qryBaseinfoService.getConbinList(id);
		if((detailList!=null)&&(detailList.size()>0))
			nodeList.addAll(detailList);
		return nodeList;		
	}
	
	@RequestMapping("/getOne.action")
	public SupplyBaseType getOne(@RequestParam(value="id",required=false) Long id){
		return super.getOne(id);
	}

}
